<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <p id="ptime"></p>

    <input type="button" onclick="stopTime()" value="确定">
</body>

<script>
    //setInterval是循环调用
    var mytime  = setInterval(function(){
        var d = new Date();
        var t = d.toLocaleTimeString();
        document.getElementById('ptime').innerHTML = t;

    },1000);


    function stopTime() {
        clearInterval(mytime);
    }


    // var win;
    function myWin() {
        alert('hello');
        //setTimeout只执行调用一次
        win =  setTimeout(function () {myWin() },3000);
    }

    function stopWin() {
        clearTimeout(win);
    }

</script>
</html>